package org.wang.excelfromtobean.common.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wang.excelfromtobean.common.entity.TestEntity;
import org.wang.excelfromtobean.common.response.ResponseResult;
import org.wang.excelfromtobean.common.util.ExcelToObjectUtil;

import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

/**
 * @ClassName testController
 * @Desription TODO:
 * @Author wangchong
 * @Date 2024/6/17 10:13
 * @Version 1.0
 **/
@RestController
@AllArgsConstructor
@RequestMapping("test")
@Api(value = "kq指令接口", tags = "kq指令接口")
public class TestController {

    /**
     * 读取excel转成文本
     *
     * @return 删除结果
     */
    @GetMapping("/excelToBean")
    @ApiOperation(value = "读取excel转成文本", notes = "")
    public ResponseResult excelToBean() {
        String excelFilePath = "E:\\Xm\\Study\\ExcelFromToBean\\src\\main\\resources\\templates\\341202002004GB00001.xlsx"; // 确保此路径指向实际的测试Excel文件
        String configFilePath = "E:\\Xm\\DJDCCGSH\\backend\\src\\main\\resources\\templates\\test.json"; // 如果有配置文件，指定其路径，否则留空
        Map<String, Object> result = null;
        try {
            result = ExcelToObjectUtil.convert(Map.class, excelFilePath, configFilePath, 1);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ResponseResult.success(result);
    }


    public static void main(String[] args) throws IOException, ParseException, IllegalAccessException, InstantiationException {
        String excelFilePath = "E:\\Xm\\Study\\excel-from-to-bean\\src\\main\\resources\\templates\\341202002004GB00001.xlsx"; // 确保此路径指向实际的测试Excel文件
        String configFilePath = "E:\\Xm\\Study\\excel-from-to-bean\\src\\main\\resources\\templates\\test.json"; // 如果有配置文件，指定其路径，否则留空
        Map<String, Object> convert = ExcelToObjectUtil.convert(excelFilePath, configFilePath, 0);
        System.out.println(convert);
    }

}
